//5
//10 5 0 1 3 2
//30
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m; // n表示最大阶数, m表示用户需求数
let initArr = [];
rl.on("line", (line)=>{
    if(n === undefined) {
        n = Number(line.trim())
    } else if (initArr.length === 0) {
        initArr = line.trim().split(/\s+/).map(Number)
    } else if (m === undefined) {
        m = Number(line.trim())
        console.log(getResult(n, m, initArr))

        // clear
        n = m = undefined
        initArr.length = 0
    }

})

function getResult(n, m, initArr) {
    let arr = []
    for (let i = 0; i < initArr.length ; i++) {
        let obj = {
            count: initArr[i],
            number: Math.pow(2, i)
        }
        arr.push(obj)
    }

    // 信道按值的升序排序
    arr.sort((a, b) => a.number - b.number)

    //  开始分配, 先分配大的, 如果不足, 再分配小的, 直到分配完毕
    let ans = 0
    let remain = arr.reduce((acc, obj) => acc + obj.number * obj.count, 0)
    outer:while(remain >= m) {
        let need = m
        // 先取大块
        for (let i = arr.length - 1; i >= 0 ; i--) {
            let obj = arr[i]
            if(obj.count === 0) continue
            while(need - obj.number >= 0 && obj.count > 0) {
                need -= obj.number
                remain -= obj.number
                obj.count--
            }
            if(need === 0) {
                ans++
                continue outer
            }
        }


        // 再取小块
        for (let i = 0; i <= arr.length - 1 ; i++) {
            let obj = arr[i]
            if(obj.count === 0) continue


            while(need > 0){
                need -= obj.number
                remain -= obj.number
                obj.count--
            }

            if(need <= 0) {
                ans++
                continue outer
            }
        }
    }
    return ans
}